package com.chb.jblog.ext.jetfunctions;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;

public class StringMethods {
	public static String link(String text, String url) {
		return "<a href=\"" + url + "\">" + text + "</a>";
	}
	
	public static String chb(String chb){
		return "chenbing";
	}
	
	public static String selectOptions(Map<?,?> options, Object value) {
	    StringBuffer sb = new StringBuffer();
	    for (Map.Entry<?,?> entry: options.entrySet()) {
	        sb.append("<option value=\"");
	        sb.append(entry.getKey());
	        sb.append("\"");
	        if (value != null && value.toString().equals(entry.getKey().toString())) {
	            sb.append(" selected");
	        }
	        sb.append(">");
	        sb.append(entry.getValue());
	        sb.append("</option>");
	    }
	    return sb.toString();
	}
	 
	public static String selectOptions(List<?> options, Object value) {
	    StringBuffer sb = new StringBuffer();
	    System.out.println("value:"+value);
	    System.out.println(JSON.toJSONString(options));
	    for (Object item: options) {
	    	System.out.println(item);
	        sb.append("<option");
	        if (value != null && value.toString().equals(item.toString())) {
	            sb.append(" selected");
	        }
	        sb.append(">");
	        sb.append(item);
	        sb.append("</option>");
	        System.out.println(sb);
	    }
	    return sb.toString();
	}
}
